<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/3/4
 * Time: 21:30
 */

class OrderformModel extends RelationModel{

    public $table = 'orderlist';

    public $relation=array(
        'ordernumber' => array(
            'type' => HAS_ONE,
            'parent_key' => 'oid',
            'foreign_key' => 'order_oid',
        ),
        'goods' => array(
            'type' => HAS_ONE,
            'parent_key' => 'gid',
            'foreign_key' => 'gid',
        ),
    );

    //表单验证
    public $validate = array(
        //商品名验证
        array('ocont','nonull','商品名不能为空',1,3),
        //商品数量验证
        array('onum','nonull','商品数量不能为空',1,3),
        array('onum','regexp:/^[0-9]*$/','商品数量只能位数字',1,3),
        //地址验证
        array('address','nonull','地址栏不能为空',1,3),
        //上传图片验证
        array('oimg','nonull','图片不能为空',1,3),
        //手机号
        array('admoblie','phone','手机号码错误',1,3),
        //姓名
        array('adname','nonull','姓名不能为空',1,3),
    );

    //查询用户订单量
    public function selc_num($where=''){
        return $this -> where($where) -> count();
    }

    //获取订单详情
    public function selc_info($where ='',$limit =''){
        return $this -> limit($limit) -> where($where) -> all();
    }

    //添加用户订单
    public function add_order($data){
        return $this -> add($data);
    }

    //获取单个订单详细
    public function get_one($where){
        return $this -> find($where);
    }
    //修改用户订单
    public function up_order($data,$where){
        return $this -> where($where) -> save($data);
    }
    //删除用户订单
    public function del_order($where){
        return $this -> where($where) -> del();
    }
}